import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: uni.getStorageSync('uni_id_token') && uni.getStorageSync('uni_id_token_expired') > Date.now(),
		role: uni.getStorageSync('role'),
		userInfo:uni.getStorageSync('userInfo')||{},
		hasLogin: uni.getStorageSync('uni_id_token')
	},
	mutations: {
		login(state, {
			token,
			tokenExpired,
			userinfo,
			role
		}) {
			uni.setStorageSync('uni_id_token', token)
			uni.setStorageSync('uni_id_token_expired', tokenExpired)
			uni.setStorageSync('userinfo', userinfo)
			uni.setStorageSync('role', role)
			state.hasLogin = true
			state.userInfo = userinfo
			state.role = role
			state.uni_id_token=token
		},
		logout(state) {
			uni.removeStorageSync('uni_id_token')
			uni.removeStorageSync('uni_id_token_expired')
			uni.removeStorageSync('userInfo')
			uni.removeStorageSync('role')
			state.hasLogin = false
			state.userInfo = null
			state.role = null
		},
		
	},
	actions:{
		
	}
})

export default store
